﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Perseus.WCF.REST.Contract.Data;
using Perseus.WCF.DAL;
using System.Data;

namespace Perseus.WCF.Sequence
{
    public class GetAllEmpFlow : IListFlow<Employee>
    {
        public IList<Employee> GoList()
        {
            SqlDbUtil db = new SqlDbUtil();
            string sql = "select FirstName, LastName, BirthDate from Employees";
            DataSet ds = db.GetDataSet(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                List<Employee> mylist = new List<Employee>();
                string firstName;
                string lastName;
                DateTime birthDate;

                for (int i=0; i<ds.Tables[0].Rows.Count; i++)
                {
                    firstName = ds.Tables[0].Rows[i]["FirstName"].ToString();
                    lastName = ds.Tables[0].Rows[i]["LastName"].ToString();
                    birthDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["BirthDate"].ToString());
                    mylist.Add(new Employee(firstName, lastName, birthDate));
                }

                return mylist;
            }

            return null;
        }
    }
}
